package com.nanyang.tms.controller.forecast;

import com.nanyang.common.core.annotation.BindParam;
import com.nanyang.common.core.dict.CommonEnum;
import com.nanyang.common.core.domain.ApiResult;
import com.nanyang.common.core.exception.ServiceException;
import com.nanyang.tms.api.dto.request.forecast.ForecastInfoAddRequest;
import com.nanyang.tms.api.service.forecast.ForecastCoreRpcService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/forecast")
public class ForecastController {
	 @Reference(version = "1.0.0", timeout = 10000, check = false)
	 private ForecastCoreRpcService forecastCoreRpcService;
   
	 @BindParam
	 @RequestMapping(value = "/add", method = RequestMethod.POST)
	 public ApiResult<Boolean> insertForecast (@Valid @RequestBody @BindParam ForecastInfoAddRequest forecastInfoAddRequest){
		
		 ApiResult<Boolean> apiResult = new ApiResult<Boolean>();
			 apiResult= forecastCoreRpcService.insertForecast(forecastInfoAddRequest);
			  if (apiResult.getCode() == CommonEnum.SYSTEM_EXCEPTION.getCode()) {
		            throw new ServiceException(CommonEnum.SYSTEM_EXCEPTION.getCode(), apiResult.getMessage());
		        }
		 return apiResult;
	 }
}
